package tools.crawler.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Scanner;

import org.junit.Test;

import com.easywan.util.Utils;

public class TtoMysql {
	@Test
	public void test() throws FileNotFoundException, SQLException, ClassNotFoundException{
			Class.forName("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1/easywan","root","");
			PreparedStatement pstmt = conn.prepareStatement("insert into article(createtime,title,context,uid) values(?,?,?,1)");
		File file = new File("D:\\html\\travle\\data");
		String[] files = file.list();
		System.out.println(Arrays.toString(files));
		for(String filePath:files){
			File fileTmp = new File("D:\\html\\travle\\data\\"+filePath);
			String context = "";
			FileInputStream is = new FileInputStream(fileTmp);
			Scanner scan = new Scanner(is);
			while(scan.hasNext()){
				context += scan.nextLine();
			}
			//System.out.println(context);
			String[] cs = context.replace("{", "").split("}");
			System.out.println(Arrays.toString(cs));
			if(cs != null && cs.length > 0){
					pstmt.setString(1, cs[1]);
					pstmt.setString(2, cs[0]);
					pstmt.setString(3, cs[2]);
					int i = pstmt.executeUpdate();
					System.out.println(i);
			}
		}
	}
}
